package 简单多状态;

public class test6 {

    public int maxProfit(int[] prices, int fee) {
        // 分两种:买入,卖出,卖出的时候交手续费
        int n = prices.length;
        int[] dp1 = new int[n];// 买入
        int[] dp2 = new int[n];// 卖出
        dp1[0] = -prices[0];
        for (int i = 1; i < n; i++) {
            dp1[i] = Math.max(dp1[i-1],dp2[i-1]-prices[i]);
            dp2[i] = Math.max(dp1[i-1]+prices[i]-fee,dp2[i-1]);
        }
        return dp2[n-1];
    }
}
